package cc.vv.btpartyjob.partymanager.view

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.AddResourceObj
import cc.vv.lkbasecomponent.util.LKScreenUtil
import java.util.*

/**
 * 报到资源
 * Created by  Chen.qi on 2018/10/29.
 */
class ReportResourceView : LinearLayout {
    /**
     * 上下文
     */
    private var mContext: Context? = null
    /**
     * 父布局
     */
    private var llSelectedAll: LinearLayout? = null

    constructor(context: Context) : this(context, null) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        mContext = context
        val inflateView = View.inflate(context, R.layout.layout_operation_view, null)
        llSelectedAll = inflateView.findViewById(R.id.ll_lov_showAll)
        this.addView(inflateView)
    }


    @SuppressLint("SetTextI18n")
            /**
             * 填充选项数据
             *
             * @param optionList 数据集
             */
    fun addAllSelectedFileView(optionList: ArrayList<AddResourceObj>?) {
        if (null == optionList) {
            return
        }
        //清除
        clearAllJobOptionView()
        val topAll = LayoutParams(LKScreenUtil.getScreenWidth() - LKScreenUtil.dp2px(26f),
                LKScreenUtil.dp2px(70f))

        for (i in 0 until optionList.size) {
            val view = LayoutInflater.from(mContext).inflate(R.layout.layout_report_resource, null)
            view.layoutParams = topAll
            //资源名称
            val resourceName = view.findViewById<TextView>(R.id.tv_lrr_resourceNam)
            //负责人姓名
            val principaName = view.findViewById<TextView>(R.id.tv_lrr_principalName)
            //联系电话
            val tvPhone = view.findViewById<TextView>(R.id.iv_lrr_telPhone)
            //时间
            val tvTime = view.findViewById<TextView>(R.id.tv_lrr_time)
            //方式有偿无偿
            val tvType = view.findViewById<TextView>(R.id.iv_lrr_type)

            val jobOptionObj = optionList[i]
            resourceName.text = jobOptionObj?.conetnt
            if (!TextUtils.isEmpty(jobOptionObj?.startTime)) {
                if (jobOptionObj?.startTime!!.length > 10) {
                    val substring = jobOptionObj?.startTime!!.substring(0, 10)
                    tvTime.text = "时间：$substring"
                } else {
                    tvTime.text = "时间：${jobOptionObj?.startTime}"
                }
            }

            if (jobOptionObj?.reward == 1) {
                tvType.text = "提供方式：有偿"
            } else {
                tvType.text = "提供方式：无偿"
            }

            llSelectedAll?.addView(view)

            val tv = TextView(mContext)
            val layoutParamstv = LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LKScreenUtil.dp2px(10f))
            tv.layoutParams = layoutParamstv
            llSelectedAll?.addView(tv)

        }
    }

    /**
     * 清除view
     */

    private fun clearAllJobOptionView() {
        llSelectedAll?.removeAllViews()
    }


}